/**
 * 
 */
package slhs.tempo.TableAnalyzer;

import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;

import javax.swing.JOptionPane;
import javax.swing.table.JTableHeader;
import javax.swing.table.TableColumn;
import javax.swing.table.TableColumnModel;


/**
 * MouseDoubleClickListener.java
 * 
 * @author Swapnil Devikar
 * 
 */
public class MouseClickListener implements MouseListener {

    private final TablePanelHandler tablePanelHandlerObject;

    public MouseClickListener(TablePanelHandler tablePanelHandlerObject) {
	this.tablePanelHandlerObject = tablePanelHandlerObject;
    }

    /*
     * (non-Javadoc)
     * 
     * @see java.awt.event.MouseListener#mouseClicked(java.awt.event.MouseEvent)
     */
    @Override
    public void mouseClicked(MouseEvent mouseClickedEvent) {
	JTableHeader tableHeader = (JTableHeader) mouseClickedEvent.getSource();
	if (mouseClickedEvent.getClickCount() == 2) {
	    System.out.println("Double Click in mouseClicked");
	    TableColumnModel columnModel = tableHeader.getColumnModel();
	    int eventColumnIndex = columnModel.getColumnIndexAtX(mouseClickedEvent.getX());
	    TableColumn eventColumn = columnModel.getColumn(eventColumnIndex);
	    String newHeaderName = JOptionPane.showInputDialog("Enter new column name", eventColumn.getHeaderValue()
		    .toString());
	    if (newHeaderName != null)
		eventColumn.setHeaderValue(newHeaderName);
	}
    }

    /*
     * (non-Javadoc)
     * 
     * @see java.awt.event.MouseListener#mouseEntered(java.awt.event.MouseEvent)
     */
    @Override
    public void mouseEntered(MouseEvent arg0) {

    }

    /*
     * (non-Javadoc)
     * 
     * @see java.awt.event.MouseListener#mouseExited(java.awt.event.MouseEvent)
     */
    @Override
    public void mouseExited(MouseEvent mouseExitedEvent) {
	if (mouseExitedEvent.getClickCount() == 2) {

	}

    }

    /*
     * (non-Javadoc)
     * 
     * @see java.awt.event.MouseListener#mousePressed(java.awt.event.MouseEvent)
     */
    @Override
    public void mousePressed(MouseEvent arg0) {

    }

    /*
     * (non-Javadoc)
     * 
     * @see java.awt.event.MouseListener#mouseReleased(java.awt.event.MouseEvent)
     */
    @Override
    public void mouseReleased(MouseEvent arg0) {

    }

}
